home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8823 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  49 lines

  1. Path: canopus.cc.umanitoba.ca!mwcs!bryan.schwartz
  2. From: bryan.schwartz@mwcs.mb.ca (BRYAN SCHWARTZ)
  3. Newsgroups: comp.lang.c
  4. Subject: Function Pointers
  5. Message-ID: <8BC3202.028600318C.uuout@mwcs.mb.ca>
  6. Date: Wed, 06 Mar 96 08:34:00 -0600
  7. Distribution: world
  8. Organization: Muddy Waters Computer Society inc.
  9. Reply-To: bryan.schwartz@mwcs.mb.ca (BRYAN SCHWARTZ)
  10. X-Newsreader: PCBoard Version 15.22
  11. X-Mailer: PCBoard/UUOUT Version 1.20
  12.  
  13. I'm having difficulty storing a finction address in a structure with my
  14. Borland Turbo3.0 for DOS compiler. The relevant code is as follows:
  15.  
  16. unsigned far x_get( void far *SX);   function prototype
  17. typedef union           use this union to combine attributes + chars
  18. {
  19.   unsigned ja;   char + attrib.
  20.   struct
  21.         {
  22.         char jb;  char
  23.         char jc;  attrib.
  24.       } jd;
  25. } UNI ;
  26. typedef UNI far *SX ; using far to access video memory
  27. typedef struct vid          stuct to define screen
  28. {
  29.         SX p;    current position on screen
  30.     ....code.....
  31.         unsigned( far * s_get)(SX) ;   function pointer in struct
  32. } STRU
  33.  
  34. int main(void)
  35. {
  36.         STRU *k ;   near pointer to struct
  37.         k->s_get = ( int near *)x_get ;  PROBLEM here! ????
  38.         return 0;
  39. }
  40. /* get a char + attribute from the screen using x_get() */
  41. unsigned far x_get( SX ptr )
  42. {            /* SX ptr = address in screen buffer */
  43.   return( ptr->ja );
  44.          /* return char + attrib. to union */
  45. }
  46. Shoot holes in this code, Please! And tell me about it. I'm just
  47. starting learning C. How do I store a function's address in a structure
  48. successfully?
  49.